package com.pwc.controller;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author fantuancyh
 * @data 2021/8/21
 */
@RestController
public class DelayController {
 @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("send/{message}")
    public void send(@PathVariable("message")String message){
        rabbitTemplate.convertAndSend("X","XA","延迟10秒，消息为"+message);
        rabbitTemplate.convertAndSend("X","XB","延迟20秒，消息为"+message);
        System.out.println("发送信息"+new Date().toString());
    }
    @GetMapping("send/{msg}/{time}")
    public void sendTime(@PathVariable("msg")String msg,@PathVariable("time")String time){
        MessagePostProcessor processor = (message)->{
             message.getMessageProperties().setExpiration(time);
             return message;
        };
        rabbitTemplate.convertAndSend("X","XC","延迟20秒，消息为"+msg,processor);
        System.out.println("发送信息&时间"+new Date().toString());
    }

}
